<template>
    <div>
      <h1>门店信息修改</h1>
      <table class="table">
        <thead>
            <tr>
                <td>门店编号</td>
                <td>
                  {{ data.id }}
                </td>
            </tr>
            <tr>
                <td>门店名称</td>
                <td>
                  <input type="text" v-model="data.name">
                </td>
            </tr>
            <tr>
                <td>门店数量</td>
                <td>
                    <input type="text" v-model="data.num">
                </td>
            </tr>
            <tr>
                <td>门店图片</td>
                <td>
                    <input type="file" @change="Upload">
                    <img :src="'https://localhost:7185'+data.img" style="width: 100px;height: 100px;">
                </td>
            </tr>
            <tr>
                <td>手机号</td>
                <td>
                    <input type="text" v-model="data.phone">
                </td>
            </tr>
            <tr>
                <td>门店地址</td>
                <td>
                    <input type="text" v-model="data.addr">
                </td>
            </tr>
           
            <tr>
            
                <td colspan="2">
                    <input type="button" value="修改" @click="Add">
                </td>
            </tr>
        </thead>
      </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import { useRoute } from "vue-router";
const route=useRoute();
onMounted(()=>{
    fantian();
})
const fantian=()=>{
    var x=route.query.id
    axios.get("https://localhost:7185/api/Member/Fantian",{params:{id:x}}).then(res=>{
        data.value=res.data
    })
} 
const data=ref({
    "id": 0,
  "name": "",
  "num": 0,
  "img": "",
  "phone": "",
  "addr": "",
  //"createTime": "2025-04-29T01:38:49.793Z"
})
const Add=()=>{
    axios.put("https://localhost:7185/api/Member/UpdMember",data.value).then(res=>{
        if(res.data>0){
            alert('修改成功');
            location.href='/ShowView';
        }
        else{
            alert('修改失败');
        }
    })
}
const Upload=(e:any)=>{
     var f=e.target.files[0];
     var fs=new FormData();
     fs.append("file",f);
     axios.post("https://localhost:7185/api/UpLoad/upload",fs).then(res=>{
        data.value.img=res.data
     })
     

}
</script>

<style scoped>

</style>